#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void solve(){
    int l,m;
    cin>>l>>m;
    vector<int> c(l+1,0);
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        c[l]+=1;
        c[r+1]-=1;
    }
    int sum=0;
    if(c[0])sum=1;
    else sum=0;
    for(int i=1;i<=l;i++){
        c[i]+=c[i-1];
        // cout<<c[i]<<endl;
        if(c[i]!=0)sum++;
    }
    cout<<l-sum+1<<endl;
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}